
import Vue from "vue";
import Vuex from "vuex";

// 引入数据持久化插件
import createPersistedState from "vuex-persistedstate";

// 引入不同模块
import account from "./modules/account";
import setting from "./modules/setting";
import user from "./modules/user";
import CaiGouRuKu from "./modules/CaiGouRuKu";


//挂载vuex

Vue.use(Vuex);

export default new Vuex.Store({
  state:{
      name:"智慧七河创新工程项目",
  },
  modules: {
    account,
    setting,
    user,
    CaiGouRuKu,
  },
  plugins: [
    createPersistedState({
      // key <String>: The key to store the persisted state under. Defaults to vuex.
      storage: window.localStorage, //更换到localStorage

      key: "zhqh-pro-vuex",
      

      // paths <Array>: An array of any paths to partially persist the state. If no paths are given, the complete state is persisted. If an empty array is given, no state is persisted. Paths must be specified using dot notation. If using modules, include the module name. eg: "auth.user" Defaults to undefined.
      // 可以部分保留状态的所有路径的数组。 如果未给出路径，则完整状态将保留。 如果给定一个空数组，则不会保留任何状态。 必须使用点符号指定路径。 如果使用模块，请包括模块名称。 例如：“auth.user”默认为未定义。
      // example： 默认不添加 account 模块内的数据
      // paths: ['account'],

      // reducer <Function>: A function that will be called to reduce the state to persist based on the given paths. Defaults to include the values.
      // 一个将被调用的函数，用于根据给定路径减少状态以使其持久。默认情况下包含这些值。
      // example： 设置需要对 account 内的数据进行数据持久化
      // reducer(state) {
      //   return {
      //     account: state.account
      //   }
      // },

      // TODO ----
      // subscriber <Function>: A function called to setup mutation subscription. Defaults to store => handler => store.subscribe(handler).
      // subscriber(...options) {
      //   console.log(options);
      // },

      // storage <Object>: Instead of (or in combination with) getState and setState. Defaults to localStorage.
      // 设置存储位置
      // example-one: 更改存储位置为 localStorage
      // storage: window.localStorage,
      // example-two: 对拿、存、删数据进行额外操作
      // import SecureLS from "secure-ls";
      // var ls = new SecureLS({ isCompression: false });
      // storage: {
      //   getItem: (key) => ls.get(key),
      //   setItem: (key, value) => ls.set(key, value),
      //   removeItem: (key) => ls.remove(key),
      // },

      // getState <Function>: A function that will be called to rehydrate a previously persisted state. Defaults to using storage.
      // 一个函数，它将被调用来重新生成以前持久化的状态。默认使用存储。
      // example: 从 storage 中获取数据可进行重新拼接
      // getState(key,storage){
      //   console.log(key,storage);
      //   return storage[key]
      // },

      // TODO -----
      // setState <Function>: A function that will be called to persist the given state. Defaults to using storage.
      // 将被调用以保持给定状态的函数。 默认为使用存储。
      // example: 可进行自定义存储 State 数据
      // setState(key, state, storage) {
      //   console.log(key, state, storage);
      //   return { account: state.account }
      // },

      // overwrite <Boolean>: When rehydrating, whether to overwrite the existing state with the output from getState directly, instead of merging the two objects with deepmerge. Defaults to false.
      // 刷新后取值时，是否直接用getState的输出覆盖现有状态，而不是使用deepmerge将两个对象合并。 默认为false。
      // overwrite: true

      // TODO -----
      // filter <Function>: A function that will be called to filter any mutations which will trigger setState on storage eventually. Defaults to () => true.
      // 一个函数，将被调用来过滤任何突变，这些突变将最终触发存储上的setState。默认值为()=> true。
      // filter(...options) {
      //   console.log(options);
      //   return true
      // }

      // arrayMerger <Function>: A function for merging arrays when rehydrating state. Defaults to function (store, saved) { return saved } (saved state replaces supplied state).

      // rehydrated <Function>: A function that will be called when the rehydration is finished. Useful when you are using Nuxt.js, which the rehydration of the persisted state happens asynchronously. Defaults to store => {}

      // fetchBeforeUse <Boolean>: A boolean indicating if the state should be fetched from storage before the plugin is used. Defaults to false.

      // assertStorage <Function>: An overridable function to ensure storage is available, fired on plugins's initialization. Default one is performing a Write-Delete operation on the given Storage instance. Note, default behaviour could throw an error (like DOMException: QuotaExceededError).
    }),
  ],
});
